/**
 * There are so many tricky parts here.
 * I believe TC has a nice test part this time.
 */

/**
 * @author antonio081014
 * @since Feb 9, 2012, 8:09:45 AM
 */
import java.util.ArrayList;
import java.util.List;

public class DengklekMakingChains {
    public int maxBeauty(String[] chains) {
        int N = chains.length;
        List<String> newChain = new ArrayList<String>();
        int count = 0;
        for (int i = 0; i < chains.length; i++) {
            if (chains[i].contains(".") == false) {
                count += chains[i].charAt(0) - '0';
                count += chains[i].charAt(1) - '0';
                count += chains[i].charAt(2) - '0';
            }
            else {
                newChain.add(chains[i]);
            }
        }
        int max = 0;
        int max2 = 0;
        for (int i = 0; i < newChain.size(); i++) {
            int tmp = 0;
            for (int k = 2; k >= 0; k--)
                if (newChain.get(i).charAt(k) != '.')
                    tmp += newChain.get(i).charAt(k) - '0';
                else
                    break;
            int tmp3 = 0;
            for (int k = 0; k < 3; k++)
                if (newChain.get(i).charAt(k) != '.')
                    tmp3 += newChain.get(i).charAt(k) - '0';
                else
                    break;
            max2 = Math.max(max2, newChain.get(i).charAt(1) - '0');
            max = Math.max(max, tmp);
            max = Math.max(max, tmp3);
            for (int j = 0; j < newChain.size(); j++) {
                if (i != j) {
                    int tmp2 = 0;
                    for (int k = 0; k <= 2; k++)
                        if (newChain.get(j).charAt(k) != '.')
                            tmp2 += newChain.get(j).charAt(k) - '0';
                        else
                            break;
                    max = Math.max(max, tmp + tmp2);
                }
            }
        }
        return Math.max(count + max, max2);
    }

    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!
